package com.googlecode.geoteacher.db.model;

import java.util.Date;

/**
 * Model class for the game database table {@code challenge_result}.
 */
public class ChallengeResult {

	/**
	 * Unique ID column.
	 */
	private long id;

	/**
	 * Foreign key to table {@code challenge}.
	 */
	private long challengeId;

	/**
	 * Actual result is a distance in kilometers.
	 */
	private int distance;

	/**
	 * Time stamp for when it was inserted. This is saved as a long integer in
	 * the database.
	 */
	private Date created;

	public ChallengeResult() {
	}

	public ChallengeResult(long challengeId, int distance, Date created) {
		this.challengeId = challengeId;
		this.distance = distance;
		this.created = created;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getChallengeId() {
		return challengeId;
	}

	public void setChallengeId(long challengeId) {
		this.challengeId = challengeId;
	}

	public int getDistance() {
		return distance;
	}

	public void setDistance(int distance) {
		this.distance = distance;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (challengeId ^ (challengeId >>> 32));
		result = prime * result + ((created == null) ? 0 : created.hashCode());
		result = prime * result + distance;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ChallengeResult other = (ChallengeResult) obj;
		if (challengeId != other.challengeId)
			return false;
		if (created == null) {
			if (other.created != null)
				return false;
		} else if (!created.equals(other.created))
			return false;
		if (distance != other.distance)
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ChallengeResult [id=" + id + ", challengeId=" + challengeId
				+ ", distance=" + distance + ", created=" + created + "]";
	}
}